import { ref } from 'vue';
import api from '../api/api';

export const useDeleteArticle = (id) => { 
    // 删除文章
    const deleteArticle = async (id) => {
    if (!confirm('确定要删除这篇文章吗？')) return;

    try {
        const response = await api.delete(`/articles/auth/${id}`);

        if (response.data.code === 1 && response.data.msg === 'success') {
        alert('删除成功');
        } else {
        alert('删除失败');
        }
    } catch (err) {
        console.error('请求出错:', err);
        alert('网络错误，请重试');
    }
    };

    return { deleteArticle };
};